 //index.js
//获取应用实例
const app = getApp()
const constant = require('../../constant');

Page({
  data: {
    advImgs: [''],
    indicatorDots: true,
    autoplay: true,
    interval: 5000,
    duration: 1000,
    hottrucklist: [],
    hottrucktypelist: [],
    hotinsurancelist: []
  },
  //事件处理函数
  bindViewTap: function() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  onLoad: function () {
      this.getAdvImageList();
      this.getHottruckList();
      this.getHottrucktypeList();
      this.getHotinsuranceList();
  },
  getAdvImageList() {
    let that = this;
    app.get('Site/getadvlist', {
      type: ''
    }, function (res) {
      if (res.code == 200 && res.data.length > 0) {
        var list = [];
        for (let i = 0; i < res.data.length; i++) {
          res.data[i].img = constant.config.host + res.data[i].img;
          list.push(res.data[i])
        }
        that.setData({
          advImgs: list,
        })
      }
    })
  },
  getHottruckList() {
    let that = this;
    app.get('Goods/getproductlist', {
      type: '6,7',
      ishot: '1',
      page_no: '1',
      page_count: '4'
    }, function (res) {
      if (res.code == 200 && res.data.data_list.length > 0) {
        let list = res.data.data_list
        for (let i = 0; i < list.length; i++) {
          list[i].goods_img = constant.config.host + list[i].goods_img;
        }
        that.setData({
          hottrucklist: list,
        })
      }
    })
  },
  getHottrucktypeList() {
    let that = this;
    app.get('Goods/gettruckcatlist', {
      type: '6,7',
      ishot: '1',
      page_no: '1',
      page_count: '3'
    }, function (res) {
      if (res.code == 200 && res.data.data_list.length > 0) {
        let list = res.data.data_list;
        for (var i = 0; i < list.length; i++) {
          list[i].img = constant.config.host + list[i].img;
        }
        that.setData({
          hottrucktypelist: list,
        })
      }
    })
  },
  getHotinsuranceList() {
    let that = this;
    app.get('Goods/getproductlist', {
      type: '3,8,9',
      ishot: '1',
      page_no: '1',
      page_count: '3'
    }, function (res) {
      if (res.code == 200 && res.data.data_list.length > 0) {
        let list = res.data.data_list
        for (let i = 0; i < list.length; i++) {
          list[i].goods_img = constant.config.host + list[i].goods_img;
        }
        that.setData({
          hotinsurancelist: list,
        })
      }
    })
  },
  //导航跳转
  toCarDetail: function (event) {
    //车型详情跳转
    var goods_id = event.currentTarget.dataset.id;
    wx.navigateTo({
      url: '../carDetail/carDetail?goods_id=' + goods_id
    })
  },
  toCartypeDetail: function (event) {
    //车系详情跳转
    var item = event.currentTarget.dataset.item;
    var id = item.titlecat_id;
    var imgTitle = item.img_title;
    var price = item.price;
    if (price == '' || price == null) price = '暂无报价';
    var title = item.title;
    wx.navigateTo({
      url: '../carTypeDetail/carTypeDetail?id=' + id + '&img=' + imgTitle + '&title=' + title + '&price=' + price
    })
  },
  buyCar: function () {
    wx.navigateTo({
      url: '../buyCar/buyCar'
    })
  },
  toInsure: function () {
    wx.navigateTo({
      url: '../insurance/insurance'
    })
  },
  toOldCar: function () {
    wx.navigateTo({
      url: '../usedCar/usedCar'
    })
  },
  toMall: function () {
    wx.switchTab({
      url: '../mall/mall'
    })
  },
  regeist: function () {
    wx.navigateTo({
      url: '../login/login'
    })
  },
  toLoan: function () {
    wx.navigateTo({
      url: '../loan/loan'
    })
  },
  toMore: function() {
    wx.navigateTo({
      url: '../comeSoon/comeSoon'
    })
  },
  toMyCard: function () {
    wx.navigateTo({
      url: '../comeSoon/comeSoon'
    })
  },
  findMoreCarType: function (){
    wx.navigateTo({
      url: '../findCar/findCar'
    })
  },
  toCarBrand: function () {
    wx.navigateTo({
      url: '../carBrand/carBrand'
    })
  },
  toInsurance: function () {
    wx.navigateTo({
      url: '../insurance/insurance'
    })
  },
  toInsuranceDetails: function (event) {
    var id = event.currentTarget.dataset.id;
    wx.navigateTo({
      url: '../insuranceDetails/insuranceDetails?goods_id=' + id
    })
  },
})
